 <?php

if (isset($_POST['season']) && isset($_POST['playerID'])) {
	
include_once './db_bb_connect.php';

$playerID =  $_POST['playerID'];
$season = $_POST['season'];


$sql = "SELECT SUM(DRB) AS SUMDRB,  SUM(ORB) AS SUMORB, SUM(TOV) AS SUMTOV, SUM(ST) AS SUMST, SUM(FTscored) AS SUMFTscored, SUM(FTtotal) AS SUMFTtotal, SUM(FGscored) AS SUMFGscored, SUM(FGtotal) AS SUMFGtotal, SUM(PF) AS SUMPF, 
(SELECT COUNT(*) FROM stats WHERE DNP != 'no' AND playerID = '$playerID' AND season = '$season' ) AS DNPtot, 
(SELECT COUNT(*) FROM stats WHERE DNP = 'yes' AND playerID = '$playerID' AND season = '$season' ) AS DNPgen, 
(SELECT COUNT(*) FROM stats WHERE DNP = 'coach' AND playerID = '$playerID' AND season = '$season' ) AS DNPcoach, 
(SELECT COUNT(*) FROM stats WHERE DNP = 'injury' AND playerID = '$playerID' AND season = '$season' ) AS DNPinjury, 
COUNT(*) AS TOTALGAMES
FROM stats 
WHERE playerID = '$playerID' 
AND season = '$season'";

$result=$db->query($sql);

$row=$result->fetch_assoc();

$SUMDRB = $row['SUMDRB']; 
$SUMORB = $row['SUMORB']; 
$SUMTOV = $row['SUMTOV']; 
$SUMST = $row['SUMST']; 
$SUMFTscored = $row['SUMFTscored']; 
$SUMFTtotal = $row['SUMFTtotal']; 
$SUMFGscored = $row['SUMFGscored']; 
$SUMFGtotal = $row['SUMFGtotal'];
$SUMPF = $row['SUMPF'];  
$DNPtot = $row['DNPtot'];
$TOTALGAMES = $row['TOTALGAMES'];    
$DNPcoach = $row['DNPcoach'];   
$DNPinjury = $row['DNPinjury'];   



?>

<div class="container-fluid">
	<div class="row">
		<div class="col-md-12">
			<div class="table-responsive">
			<h4>Cumulative stats of <?= $season; ?>  </h4>
			<table class="table table-hover table-striped">
			    <thead>
			      <tr>
			        <th>DRB</th>
			        <th>ORB</th>
			        <th>TO</th>
			        <th>ST</th>
			        <th>PF</th>
			        <th>FT</th>
			        <th>FG</th>
			        <th>PTS</th>
			        <th>DNP</th>
			    </thead>
			    <tbody>
			    	<td><?= $SUMDRB; ?></td>
			    	<td><?= $SUMORB; ?></td>
			    	<td><?= $SUMTOV; ?></td>
			    	<td><?= $SUMST; ?></td>
			    	<td><?= $SUMPF; ?></td>
			    	<td><?= $SUMFTscored; ?>/<?= $SUMFTtotal; ?> (<?= round(($SUMFTscored/$SUMFTtotal)*100); ?>%) </td>
			    	<td><?= $SUMFGscored; ?>/<?= $SUMFGtotal; ?> (<?= round(($SUMFGscored/$SUMFGtotal)*100); ?>%)</td>
			    	<td><?= 2 * $SUMFGscored + $SUMFTscored; ?></td>
			    	<td><?= $DNPtot; ?>/<?= $TOTALGAMES; ?> (I:<?= $DNPinjury; ?> C:<?= $DNPcoach; ?>)</td>


			    </tbody>
			  </table>
			</div>
	</div>
</div>

<?php
}

?>


